package com.lee.rpc.protocal.spring.reference;

import java.lang.reflect.Proxy;

import org.springframework.beans.factory.FactoryBean;

public class SpringRpcReferenceBean implements FactoryBean<Object>{

	private String serverAddress;
	private int serverPort;
	private Class<?> interfaceClass;
	
	
	/**
	 * 实现了FactoryBean
	 * 1)会生成一个工厂bean对象SpringRpcReferenceBean
	 * 2)会生成一个实例对象(getObject返回的对象)并且放到spring容器里面去
	 * */
	@Override
	public Object getObject() throws Exception {
		// TODO Auto-generated method stub
		//生成代理对象,接口
		//invoke方法会建立连接，端口，地址
		return Proxy.newProxyInstance(
				interfaceClass.getClassLoader(), 
				new Class<?>[] {interfaceClass}, 
				new RpcInvokeProxy(serverAddress, serverPort));
	}

	@Override
	public Class<?> getObjectType() {
		// TODO Auto-generated method stub
		return this.interfaceClass;
	}

	
	public String getServerAddress() {
		return serverAddress;
	}

	public void setServerAddress(String serverAddress) {
		this.serverAddress = serverAddress;
	}

	public int getServerPort() {
		return serverPort;
	}

	public void setServerPort(int serverPort) {
		this.serverPort = serverPort;
	}

	public Class<?> getInterfaceClass() {
		return interfaceClass;
	}

	public void setInterfaceClass(Class<?> interfaceClass) {
		this.interfaceClass = interfaceClass;
	}

	
	

	

}
